<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.css" rel="stylesheet" />
		<link href="../css/main.css" rel="stylesheet" />
		<link href="../css/login.css" rel="stylesheet" />
		
	</head>

	<body >
		<header class="mui-bar mui-bar-nav ">
			<div class="mui-margin-25"></div>
			<h1 class="mui-title">登录</h1>
		</header>
		<div class="mui-content" >
			<!-- 组件 -->
			<div class="form-container">
				<div class="form-img">
					<img  src="../img/logo.png">
				</div>
				<div class="form-group-box">
					<div class="form-group-input" tabindex="1">
						<input type="text" placeholder="账号" id="username"/>
					</div>
					<div class="form-group-input" tabindex="2">
						<input type="password" placeholder="密码" id="password"/>
					</div>
					<div class="form-btn" >
						<span>登录</span>
					</div>
				</div>
				
				<div class="link-group">
					<a href="javaScrpit:" class="regist-btn">注册账号</a>
					<a href="javaScrpit:" class="wangjimima-btn">忘记密码</a>
				</div>
			</div>
		</div>
		
		
		<script src="../js/mui.js"></script>
		<script src="../js/jquery-3.1.1.min.js"></script>
		<script src="../js/main.js" type="text/javascript">
			
		</script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function () {
				initDocumentHeight()
				const currentWebview = plus.webview.currentWebview();
				
				currentWebview.addEventListener("show",function(){
					plus.nativeUI.closeWaiting();
					if(currentWebview.waitCloseWebView){
						var indexWebview = plus.webview.getWebviewById(currentWebview.waitCloseWebView);
						if(indexWebview){
							indexWebview.close();
						}
					}
				})
				currentWebview.show();
				
				mui(".form-btn")[0].addEventListener("tap",function(){
					plus.nativeUI.showWaiting("正在请求服务,请稍后...")
					_SERVER.user.login({
						"username":$("#username").val(),
						"password":$("#password").val()
					}).then(res=>{
						plus.nativeUI.closeWaiting();
						if(res.code === "200"){
							mui.toast("登陆成功，即将跳转页面")
							// 缓存用户信息
							plus.storage.setItem("userInfo",JSON.stringify(res.data));
							// 跳转页面
							window.setTimeout(()=>{
								toIndex();
							},1500);
						}else {
							mui.toast(res.msg)
						}
					})
				})
				document.querySelector(".wangjimima-btn").addEventListener("tap",function(){
					mui.alert("该功能还未实现","提示","OK",()=>{},"div")
				})
				
				document.querySelector(".regist-btn").addEventListener("tap",function(){
					plus.webview.open("regist.html","regist",{},"slide-in-right");
				})
			
			})
			
			const toIndex = function(){
				plus.webview.open("../index.html","index",{},"auto",200)
			}
		</script>
	</body>

</html>
